Repeats the statements between the Do and the Loop statement while the condition is True or until the condition becomes True.
Do ステートメントから Loop ステートメントの間に配置されたステートメントブロックを、判定条件が True である間ないし True になるまでの間、繰り返し実行します。
Do [{While | Until} condition = True]
Do [{While | Until} condition = True]
statement block
ステートメントブロック
[Exit Do]
[Exit Do]
statement block
ステートメントブロック
Loop
Loop
or
ないしは
Do
Do
statement block
ステートメントブロック
[Exit Do]
[Exit Do]
statement block
ステートメントブロック
Loop [{While | Until} condition = True]
Loop [{While | Until} condition = True]
Condition: A comparison, numeric or string expression, that evaluates either True or False.
Condition: True ないし False として評価可能な比較条件あるいは、数値ないし文字列表式。
Statement block: Statements that you want to repeat while or until the condition is True.
ステートメントブロック: 判定条件が True である間ないしは、True になるまでの間に繰り返し実行するステートメント群。
The Do...Loop statement executes a loop as long as, or until, a certain condition is True. The condition for exiting the loop must be entered following either the Do or the Loop statement. The following examples are valid combinations:
Do...Loop ステートメントのループは、判定条件が True である間ないしは、True になるまでの間、繰り返し実行されます。ループ終了の判定条件は、Do ないし Loop ステートメントのいずれかに続けて指定する必要があります。判定条件の指定法は、下記の例を参照してください。
Do While condition = True
Do While 判定条件 = True
...statement block
...ステートメントブロック
Loop
Loop
The statement block between the Do While and the Loop statements is repeated so long as the condition is true.
この場合、Do While から Loop ステートメントまでの間にあるステートメントブロックは、判定条件が True である限り、繰り返し実行されます。
Do Until condition = True
Do Until 判定条件 = True
...statement block
...ステートメントブロック
Loop
Loop
The statement block between the Do Until and the Loop statements is repeated if the condition so long as the condition is false.
この場合、Do Until から Loop ステートメントまでの間にあるステートメントブロックは、判定条件が False である限り、繰り返し実行されます。
Do
Do
...statement block
...ステートメントブロック
Loop While condition = True
Loop While 判定条件 = True
The statement block between the Do and the Loop statements repeats so long as the condition is true.
この場合、Do から Loop ステートメントまでの間にあるステートメントブロックは、判定条件が True である限り、繰り返し実行されます。
Do
Do
...statement block
...ステートメントブロック
Loop Until condition = True
Loop Until 判定条件 = True
The statement block between the Do and the Loop statements repeats until the condition is true.
この場合、Do から Loop ステートメントまでの間にあるステートメントブロックは、判定条件が True となるまでの間、繰り返し実行されます。
Use the Exit Do statement to unconditionally end the loop. You can add this statement anywhere in a Do...Loop statement. You can also define an exit condition using the If...Then structure as follows:
ループを無条件に終了させるには、Exit Do ステートメントを使用します。このステートメントは、Do...Loop ステートメントの間の任意の位置に記述できます。また下記の例のように、ループの終了条件に If...Then を使用することもできます。
Do...
Do...
statements
ステートメント群
If condition = True Then Exit Do
If condition = True Then Exit Do
statements
ステートメント群
Loop...
Loop...
Sub ExampleDoLoop
Sub ExampleDoLoop
Dim sFile As String
Dim sFile As String
Dim sPath As String
Dim sPath As String
sPath = "c:\"
sPath = "c:\"
sFile = Dir$( sPath ,22)
SFile = Dir$( sPath ,22)
If sFile <> "" Then
If sFile <> "" Then
Do
Do
MsgBox sFile
MsgBox sFile
sFile = Dir$
SFile = Dir$
Loop Until sFile = ""
Loop Until sFile = ""
End If
End If
End Sub
End Sub